package us.nchu.tomtiger.utils;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.client.RestTemplate;
import us.nchu.tomtiger.model.LuoTestResponse;

/**
 * Created by XiongXuan on 2018/1/2.
 * Luotest操作的工具类
 */
public class LuotestUtil {

    private RestTemplate restTemplate;

    @Value("${app.config.LUO_TEST_API_KEY}")
    private String api_key;

    public LuotestUtil() {
        restTemplate = new RestTemplate();
    }

    public boolean query(String value) {
        String url = "https://captcha.luosimao.com/api/site_verify?api_key=" + api_key + "&response=" + value;
        LuoTestResponse response = restTemplate.postForObject(url,null, LuoTestResponse.class);

        return response.getError() == 0;
    }
}
